package com.fencing_squad.homo.list;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import ohos.agp.components.Component;
import ohos.agp.window.dialog.CommonDialog;

import java.util.ArrayList;
import java.util.List;

public class Comment {
    String avatar = "";
    String nickname = "";
    String content = "";

    public Comment() {}

    public Comment(JSONObject object) {
        avatar = object.getString("avatar");
        nickname = object.getString("nick_name");
        JSONObject comment = object.getJSONObject("comment");
        content = comment.getString("content");
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public static List<Comment> getFromJSONArray(JSONArray array) {
        if (array == null) {
            return null;
        }
        List<Comment> comments = new ArrayList<>();
        for(int i=0; i<array.size(); i++) {
            comments.add(new Comment(array.getJSONObject(i)));
        }
        return comments;
    }
}
